package com.exam;

import com.example.app.Main;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

public class Second {
    public static void main(String[] args){
        List<User> user = new ArrayList<>();
        String temp = "10001:张三:男:1990-01-01#10002:李四:女:1989-01-09#10003:王五:男:1999-09-09#10004:刘备:男:1899-01-01#10005:孙悟空:男:1900-01-01#10006:张三:女:1999-01-01#10007:刘备:女:1999-01-01#10008:张三:女:2003-07-01#10009:猪八戒:男:1900-01-01";
        String[] users = temp.split("#");
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for(String i : users){
            String[] use = i.split(":");
            Long id = Long.parseLong(use[0]);
            String name = use[1];
            String gender = use[2];
            LocalDate birthday = LocalDate.parse(use[3], pattern);
            user.add(new User(id, name, gender, birthday));
        }
        Map<String, Integer> map = new HashMap<>();
        for(User user1 : user){
            if(map.containsKey(user1.getName())){
                map.put(user1.getName(),map.get(user1.getName()) + 1);
            }
            else{
                map.put(user1.getName(), 1);
            }

        }
        map.forEach((name, nums) -> {
            System.out.println(name + ":" + nums + "次");
        });
    }

}
